package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManagerService;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.vo.MovementsVo;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/manage")
public class ManagerController {
    @Autowired
    private ManagerService managerService;

    /**
     * 用户管理基本资料列表
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/users")
    public ResponseEntity findUsers(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult result = managerService.findUsers(page, pagesize);
        return ResponseEntity.ok(result);
    }

    /**
     * 通过id查询 用户基本资料
     *
     * @param userId
     * @return
     */
    @GetMapping("/users/{userId}")
    public ResponseEntity findByUserId(@PathVariable("userId") Long userId) {
        //通过id查询 用户详情
        UserInfo userInfo = managerService.findByUserId(userId);
        return ResponseEntity.ok(userInfo);
    }

    /**
     * 根据id视频记录翻页
     *
     * @param page
     * @param pagesize
     * @param uid
     * @return
     */
    @GetMapping("/videos")
    public ResponseEntity findByVideo(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize,
                                      Long uid) {
        PageResult result = managerService.findByVideo(page, pagesize, uid);
        return ResponseEntity.ok(result);
    }

    /**
     * 动态分页记录
     *
     * @param page
     * @param pagesize
     * @param uid
     * @param state
     * @return
     */
    @GetMapping("/messages")
    public ResponseEntity findMessages(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize,
                                       Long uid, String state) {
        if ("''".equals(state) || "".equals(state)) {
            state = null;
        }
        PageResult result = managerService.findMessages(page, pagesize, uid, state);
        return ResponseEntity.ok(result);
    }

    /**
     * 动态详情查询
     *
     * @return
     */
    @GetMapping("/messages/{id}")
    public ResponseEntity findAllMessages(@PathVariable("id") String id) {
        MovementsVo movementsVo = managerService.findMovment(id);
        return ResponseEntity.ok(movementsVo);
    }

    /**
     * 根据动态查询单条动态详情
     *
     * @return
     */
    @GetMapping("/messages/comments")
    public ResponseEntity findComments(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize,
                                       String messageID) {
        PageResult pageResult = managerService.findComments(page, pagesize, messageID);
        return ResponseEntity.ok(pageResult);
    }


    /**
     * 用户冻结
     *
     * @return
     */
    @PostMapping("/users/freeze")
    public ResponseEntity usersFreeze(@RequestBody Map map) {
        Map resultMap = managerService.usersFreeze(map);
        return ResponseEntity.ok(resultMap);
    }

    /**
     * 用户解结
     *
     * @return
     */
    @PostMapping("/users/unfreeze")
    public ResponseEntity usersUnFreeze(@RequestBody Map map) {
        Map resultMap = managerService.usersUnFreeze(map);
        return ResponseEntity.ok(resultMap);
    }

}
